package com.ruoyi.web.controller.order;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.OrderGoods;
import com.ruoyi.order.service.IOrderGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单卖品Controller
 *
 * @author HHAOYU
 * @date 2021-01-12
 */
@RestController
@RequestMapping("/order/orderGoods")
public class OrderGoodsController extends BaseController
{
    @Autowired
    private IOrderGoodsService orderGoodsService;

    /**
     * 查询订单卖品列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderGoods orderGoods)
    {
        startPage();
        List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单卖品列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderGoods:export')")
    @Log(title = "订单卖品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderGoods orderGoods)
    {
        List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
        ExcelUtil<OrderGoods> util = new ExcelUtil<OrderGoods>(OrderGoods.class);
        return util.exportExcel(list, "orderGoods");
    }

    /**
     * 获取订单卖品详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderGoodsService.selectOrderGoodsById(id));
    }

    /**
     * 新增订单卖品
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderGoods:add')")
    @Log(title = "订单卖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderGoods orderGoods)
    {
        return toAjax(orderGoodsService.insertOrderGoods(orderGoods));
    }

    /**
     * 修改订单卖品
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderGoods:edit')")
    @Log(title = "订单卖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderGoods orderGoods)
    {
        return toAjax(orderGoodsService.updateOrderGoods(orderGoods));
    }

    /**
     * 删除订单卖品
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderGoods:remove')")
    @Log(title = "订单卖品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderGoodsService.deleteOrderGoodsByIds(ids));
    }
}
